﻿using System;
using System.Windows.Data;
using System.Globalization;
using CRM.Tools.ODataQueryDesigner.CrmSdk;

namespace CRM.Tools.ODataQueryDesigner
{

    public class EnumBoolConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || parameter == null)
                return value;
            return value.ToString() == parameter.ToString();
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || parameter == null)
                return value;
            return Enum.Parse(targetType, (String)parameter, true);
        }

    }


    public class AttributeTextValueConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //if (value == null || parameter == null)
                return value;
            //return ((AttributeTextValue)value).Value;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (value == null)
                return value;
            return ((AttributeTextValue)value).Value;
           
        }

    }


    public class ObjectConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            object returnValue = value;

            if (value != null)
            {
                if (value.GetType() == typeof(AttributeClass ))
                    returnValue = ((AttributeClass)value) != null ? ((AttributeClass)value).SchemaName : String.Empty;
            }
            
            return returnValue;
           
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            object returnValue = value;
            if (value != null)
            {
                if (value.GetType() == typeof(EntityClass))
                {
                    //returnValue = ((EntityClass)value) != null ? ((EntityClass)value).EntityName : String.Empty;
                }
            }
            return returnValue;
           

        }
    }
}
